<?php get_instance()->view('common/header');?>
<style>
    .content-btn-box,.content-box{margin-top:10px;}
    .container {
        width: 100%;
    }
    .add-tag-btn{line-height: 40px;}
    .option-item {
        margin-bottom: 5px;
        position: relative;
    }
    .del-tag-btn{font-size: 14px;line-height: 36px;display: block;margin-bottom: 4px;}
    .del-tag-btn a{color: red;}
    .add-img{margin-top: 9px;float: left;left: 0;}
    .radio-list{float: left;}
    .delete-btn{position: absolute;top: 0;width: 200px;}
    .img-box .img{width: 150px;height: 150px}
    .img-box .img1{width: 268px;height: 202px} /*单图高宽*/
    .img-box .img2{width: 216px;height: 216px} /*多图高宽*/
    .webuploader-container > div:nth-child(2){width: 78px !important;height: 34px !important;}
    #uploader-demo .uploader-list img{width: 120px;height: 100px}
    #uploader-demo .thumbnail {width: 120px;height: 100px}
    #filePicker .webuploader-pick img{width: 110px;height: 90px}
</style>
<div class="page-container home">
    <?php get_instance()->view('common/sidebar');?>
    <div class="page-content-wrapper">
        <div class="page-content">
            <div class="row">
                <div class="col-md-12">
                    <!-- BEGIN PAGE TITLE & BREADCRUMB-->
                    <h3 class="page-title"> <?php echo $title;?></h3>
                    <ul class="page-breadcrumb breadcrumb">
                        <li class="btn-group"> <a class="btn default ml_5 return" href="<?php echo getUrl('shop/news');?>"><i class="fa fa-chevron-left"></i> 返回</a> </li>
                        <li><i class="fa fa-home"></i><a href="<?php echo getUrl('shop/news');?>">新闻列表 </a><i class="fa fa-angle-right"></i></li>
                        <li><a href="javascript:void(0);"><?php echo $add ? '添加' : '编辑';?></a></li>
                    </ul>
                    <!-- END PAGE TITLE & BREADCRUMB-->
                </div>
            </div>
            <div class="row">
                <div class="col-md-12">
                    <!-- BEGIN VALIDATION STATES-->
                    <div class="portlet box">
                        <div class="portlet-body form">
                            <!-- BEGIN FORM-->
                            <form action="<?php echo getUrl('shop/news/save')?>" class="form-horizontal" method="post" id="main-form" novalidate="novalidate">
                                <div class="form-body">
                                    <div class="form-group">
                                        <label class="control-label col-md-2">类别<span class="required">*</span></label>
                                        <div class="col-md-7" style="margin-left: 18px;">
                                            <div class="radio-list">
                                                <label class="radio-inline"><input name="type" <?php if(( ! $add && $info['type'] == 1)  || $add):?> checked<?php endif;?> value="1" type="radio"> 单图 </label>
                                                <label class="radio-inline"><input name="type" <?php if(! $add && $info['type'] == 2):?> checked<?php endif;?> value="2" type="radio"> 三图</label>
                                            </div>

                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label class="control-label col-md-2">图片<span class="required">*</span></label>
                                        <div class="img-bottom">

                                            <div id="uploader-demo">
                                                <!--用来存放item-->
                                                <div class="uploader-list">
                                                    <?php if (! $add && $info['imgs']):?>
                                                        <?php  foreach ($info['imgs'] as $v):?>
                                                            <div id="" class="file-item thumbnail pic-list">
                                                                <img src="<?php echo $v; ?>">
                                                                <a title="删除" class="delete-btn hide" href="javascript:void(0);" style="color:#b94a48;position:absolute;top:-10px;right:-5px;background-color:#ffff;height:17px;width:15px;font-size:12px;padding:2px;">
                                                                    <i class="fa fa-times"></i>
                                                                </a>
                                                                <input name="imgs[]" type="hidden" class="file-name" value="<?php echo $v; ?>">
                                                            </div>
                                                        <?php endforeach; endif;?>
                                                    <div id="filePicker" class="file-item thumbnail webuploader-container">
                                                        <div class="webuploader-pick">
                                                            <div style="position:absolute;top:0;left:0;width:100%;height:100%;padding-top:70px;color:grey;">选择图片6:5</div>
                                                            <img title="选择上传图片" src="<?php echo getDefaultImg(); ?>">
                                                        </div>
                                                        <div id="rt_rt_1c2t7atu83351ra0bvm7gcgnu1" style="position: absolute; top: 4px; left: 4px; width: 100px; height: 100px; overflow: hidden; bottom: auto; right: auto;">
                                                            <input type="file" name="file" class="webuploader-element-invisible" multiple="multiple" accept="image/*">
                                                            <label style="opacity: 0; width: 100%; height: 100%; display: block; cursor: pointer; background: rgb(255, 255, 255);">
                                                            </label>
                                                        </div>
                                                    </div>
                                                </div>
                                                <script type="text/javascript">
                                                    $(function(){
                                                        uploadImg({
                                                            box:'#uploader-demo',
                                                            uploadBtn:"#filePicker",
                                                            fileName:'imgs[]',
                                                            width:240,  //显示缩略图宽带
                                                            uploadUrl:'<?php echo getUrl('shop/news/uploadImgs');?>',
                                                            height:200,	//显示缩略图高度
                                                            number:3
                                                        });

                                                    });

                                                </script>
                                            </div>
                                        </div>

                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-md-2">所属分类</label>
                                        <div class="col-md-9">
                                            <select class="form-control sel" multiple name="typeIds[]" data-placeholder="请选择所属分类">
                                                <?php foreach ($category as $v): ?>
                                                    <?php if(!$add && in_array($v['id'],$info['type_ids'])): ?>
                                                        <option value="<?php echo $v['id']?>" selected ><?php echo $v['type_name']?></option>
                                                    <?php else: ?>
                                                        <option value="<?php echo $v['id']?>" ><?php echo $v['type_name']?></option>
                                                    <?php endif;?>
                                                <?php endforeach;?>
                                            </select>
                                        </div>
                                    </div>
                                    <script type="text/javascript">
                                        $(function () {
                                            $(".sel").select2();
                                        });
                                    </script>
                                    <div class="form-group">
                                        <label class="control-label col-md-2">新闻标题<span class="required">*</span></label>
                                        <div class="col-md-9">
                                            <input class="form-control required" name="title" type="text" value="<?php echo ! $add ? $info['title'] : '';?>">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-md-2">关键词<span class="required">*</span></label>
                                        <div class="col-md-9">
                                            <input class="form-control required" name="keywords" type="text" value="<?php echo ! $add ? $info['keywords'] : '';?>">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-md-2">新闻来源<span class="required">*</span></label>
                                        <div class="col-md-9">
                                            <input class="form-control required" name="source" type="text" value="<?php echo ! $add ? $info['source'] : '暂无';?>">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-md-2">排序<span class="required">*</span></label>
                                        <div class="col-md-9">
                                            <input class="form-control required" name="sort" type="tel" value="<?php echo ! $add ? $info['sort'] : '255';?>" maxlength="11" onkeyup="(this.v=function(){this.value=this.value.replace(/[^0-9-]+/,'');}).call(this)">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-md-2">新闻内容<span class="required">*</span></label>
                                        <div class="col-md-9" >
                                            <script id="content" name="content" type="text/plain" ><?php echo !$add ? $info['content'] : ''?></script>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-md-2">是否置顶<span class="required"></span></label>
                                        <div class="col-md-9" style="margin-left: 18px;">
                                            <div class="radio-list">
                                                <label class="radio-inline"><input name="top" <?php if((! $add && $info['top'] == 1 ) || $add):?> checked<?php endif;?> value="1" type="radio"> 普通 </label>
                                                <label class="radio-inline"><input name="top" <?php if(! $add && $info['top'] == 2):?> checked<?php endif;?> value="2" type="radio"> 置顶 </label>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-md-2">状态<span class="required">*</span></label>
                                        <div class="col-md-9" style="margin-left: 18px;">
                                            <div class="radio-list">
                                                <label class="radio-inline"><input name="status" <?php if(( ! $add && $info['status'] == 2) || $add):?> checked<?php endif;?> value="2" type="radio"> 启用 </label>
                                                <label class="radio-inline"><input name="status" <?php if( ! $add && $info['status'] == 1):?> checked<?php endif;?> value="1" type="radio"> 禁用 </label>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="form-actionsc fluid">
                                        <div class="col-md-offset-2 col-md-9" style="padding-left: 0;">
                                            <input name="id" value="<?php echo ! $add ? $info['id'] : '';?>" type="hidden">
                                            <button class="btn green"><i class="fa fa-save"></i> 保存</button>
                                            <a class="btn default seach-btn" href="<?php echo getUrl('shop/news');?>"><i class="fa fa-chevron-left"></i> 返回</a>
                                        </div>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                    <!-- END VALIDATION STATES-->
                </div>
                <!-- END PAGE CONTENT-->
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(function(){
        $.e_validate.init('#main-form', {});

        UE.getEditor('content',{initialFrameWidth:'100%',initialFrameHeight:'500',autoHeightEnabled:false,serverUrl:'<?php echo getUrl('shop/news/editor');?>'});
    });

    $(function(){
        setTimeout("$('.form-actions').width($('.form-body').innerWidth()).removeClass('hide');", '500');
        window.onresize = function(){
            $('.form-actions').width($('.form-body').innerWidth());
        }
    });
</script>
</body>
</html>